<?php

class Admin extends MY_Controller {

	function Admin()
	{
		parent::MY_Controller();
	}

	function index()
	{
        //print_r($this);exit;
        parent::check_admin_login();
		$this->template->assign('title','谋成网络后台管理平台');
		$this->template->view('admin/index');
	}

    function login(){
        if($this->input->post('action') == 'login') {
            $this->load->helper('js');
            $admin_code = $this->input->post('admin_code');
            $session_code = $this->get_session_value('admincode');
            if(strtoupper($admin_code) != $session_code) {
                js_alert('验证码错误');
                js_back();
                exit();
            }
            $admin_name = $this->input->post('admin_name');
            $admin_pwd = $this->input->post('admin_pwd');
            $this->load->model('madmin');
            $flag = $this->madmin->check_admin_login($admin_name,sha1($admin_pwd));
            if($flag == '1') {
                js_alert('用户不存在');
                js_back();
                exit();
            } else if($flag == '2') {
                js_alert('密码错误');
                js_back();
                exit();
            } else if($flag == '0') {
                $this->set_admin_session($admin_name);
                js_go(base_url().'admin/');
                exit();
            } else {
                js_alert('未知错误！');
                js_back();
                exit();
            }
        }
    	$this->template->assign('title','谋成网络后台管理登录');
    	$this->template->view('admin/login');
    }

	function logout(){
    	self::unset_session_value('admin');
    	echo '<script>window.top.location.href="/admin/login/";</script>';
    	//self::redirect('注销成功',base_url().'admin/');
    }

    function top() {
    	parent::check_admin_login();
        $this->template->view('admin/admin_top');
    }

    function menu() {
    	parent::check_admin_login();
        $this->template->view('admin/left');
    }

    function right() {
        $this->template->view('admin/right');
    }


    //get admin session
    function get_admin_session()
    {
        $this->load->library('session');
        return $this->session->userdata('admin');
    }

    //set admin session
    function set_admin_session($admin_name) {
        $this->load->library('session');
        return $this->session->set_userdata('admin',$admin_name);
    }

    //get session value
    function get_session_value($key) {
        $this->load->library('session');
        return $this->session->userdata($key);
    }

}

/* End of file admin.php */
/* Location: ./app/controllers/admin.php */